<?php
$model_item             = new Default_Model_Items();
$this->headTitle('Lịch sử thiết bị','append');
?>
<div class="grid grid_8">
	<form class='frm-search frm-search-history' name='frm-search' action='/history/search' method="post" enctype="application/x-www-form-urlencoded">
		<div class='search-option-wrapper'>	
        	<div style="clear: both"></div>
			<ul class='search-option-select'>
				<li class="first">
					<label>Ngày Bắt Đầu</label>
					<input type="text" readOnly="true" id="startDate" name="startDate" value="" placeholder="mm/dd/yyyy"/>		
				</li>
				<li>
					<label>Ngày Kết Thúc</label>
					<input type="text" readOnly="true" id="endDate" name="endDate" value="" placeholder="mm/dd/yyyy"/>
				</li>
				<li>
					<label>Lọc theo hành động</label>
				</li>
				<li>
					<label>Thêm</label>
					<input class="checkbox" type="checkbox" name="sltFill_add" value="1"/>
				</li>
				<li>
					<label>Đổi dự án</label>
					<input class="checkbox" type="checkbox" name="sltFill_project" value="1"/>
				</li>
				<li>
					<label>Đổi nhóm</label>
					<input class="checkbox" type="checkbox" name="sltFill_category" value="1"/>
				</li>
                <li class="button">
                    <input type="submit" name="search"  class="submit" value="Tìm kiếm"/>
                </li>
			</ul>
            <div style="clear: both;"></div>
		</div>	
	</form>
</div>
<div class="grid grid_8">
    <div class="box table">
    	<table cellspacing="0">
            <thead>
                <tr>
                    <td class="tc">Mã Thiết Bị</td>
					<td class="tc">Item</td>
					<td class="tc">Giá Hiện Tại(Đã VAT)</td>	
                    <td class="tc">Hành Động</td>
                    <td class="tc-row">
                        <table class="table-row">
                            <tr>
                                <td class="tc-td first-row" width="16%">Thuộc Tính Cập Nhật</td>
                                <td class="tc-td" width="42%">Giá Trị Cũ</td>
                                <td class="tc-td" width="42%">Giá Trị Mới</td>
                            </tr>
                        </table>
                    </td>
                    <td class="tc">Người Sửa</td>
                    <td class="tc">Ngày Sửa</td>
                </tr>
            </thead>
            <tbody>
        	<?php foreach ($this->history as $history){ ?>
                <tr class="tr-list" id="row<?php echo $history->equipmentId; ?>">
					<td>
						<?php echo $history->equipmentName; ?>
					</td>
					<td>
						<table>
					<?php 
						$data = $model_item->getItems($history->equipmentId);
						foreach ($data as $items){
					?>							
							<tr>
								<td>
									<?php echo $items->itemName; ?>
								</td>
							</tr>																							
					<?php } ?>
						</table>
					</td>
					<td>
						<table>
					<?php 
						foreach ($data as $items){
					?>							
							<tr>
								<td>
									<?php echo number_format($items->priceNow, 0, ',', '.'); ?>
								</td>
							</tr>																							
					<?php } ?>
						</table>
					</td>
					<td>
						<?php echo $history->action; ?>
					</td>
                    <td class="tc-row">
                        <table class="table-row">
                        <?php
                			$equipmentField = json_decode($history->equipmentField);
							$valueOld = json_decode($history->valueOld);
							$valueNew = json_decode($history->valueNew);
                            for($i=0,$count=count($equipmentField); $i<$count; ++$i){
                        ?>
                            <tr>
                                <td width="16%" class="first-row"><?php echo $this->alias->$equipmentField[$i];?></td>
                                <td width="42%"><?php echo isset($valueOld[$i]) ? $valueOld[$i] : "---";?></td>
                                <td width="42%"><?php echo isset($valueNew[$i]) ? $valueNew[$i] : "---";?></td>
                            </tr>
                        <?php
                            }
                        ?>
                        </table>
                    </td>					
					<td>
						<?php echo $history->username; ?>
					</td>
					<td>
						<?php echo $this->time()->dataToDate($history->date); ?>
					</td>

                </tr>
            <?php } ?>
                </form>
            </tbody>
        </table>
    </div>
    <div class="pagination">
       <?php echo $this->paginationControl($this->paginator, 'Sliding', 'paginator.phtml'); ?>
    </div>
</div>

<script>
	$(function () {
		$("#startDate").datepicker({dateFormat: "mm/dd/yy", changeMonth : true, changeYear: true});
		$("#endDate").datepicker({dateFormat: "mm/dd/yy", changeMonth : true, changeYear: true});
	});
</script>